@extends('layouts.layouts')
@section('title')
    <title>后台首页</title>
@endsection
@section('content')
    <style type="text/css">
        table{
            width:200px;
            table-layout: fixed;
        }
        /* .autocut{
            cursor: pointer;
            overflow:hidden;
            white-space:nowrap;
            text-overflow:ellipsis;
            -o-text-overflow:ellipsis;
            -icab-text-overflow: ellipsis;
            -khtml-text-overflow: ellipsis;
            -moz-text-overflow: ellipsis;
            -webkit-text-overflow: ellipsis;
        } */
        .sweet-alert h2{font-size:14px;text-align:left;line-height: 20px;}
        .content_click{color:red;}
    </style>
    <link rel="stylesheet" href="/lib/layer/theme/default/layer.css"/>
    <script type="text/javascript" src="/lib/layer/layer.js"></script>
    <div class="content">
        <div class="header">
            <ul class="breadcrumb">
                <li>课程组作业列表</li>
                <li class="active">答案列表</li>
            </ul>
        </div>
        <div class="main-content">
            {{--<div class="btn-toolbar list-toolbar">--}}
            {{--<form class="form-inline" action="" method="get">--}}
            {{--<a href="/train/course/add"><button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" ><i class="fa fa-plus"></i> 新增</button></a>--}}
            {{--<div class="form-group">--}}
            {{--<input type="text" class="form-control" name="title" placeholder="课程标题" value="">--}}
            {{--</div>--}}
            {{--<button type="submit" class="btn btn-default">筛选</button>--}}
            {{--</form>--}}
            {{--</div>--}}
            {{--<ul class="nav nav-pills">--}}
            {{--<li role="presentation" class=" commonCourse"><a href="/course/list">课程</a></li>--}}
            {{--</ul>--}}
            <div class="row not_live_list" style="">
                <div class="col-sm-12 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading no-collapse">答案列表---《{{$question->title}}》--共有{{count($data)}}个回答</div>
                        <table class="table table-bordered table-striped">
                            <thead>
                            <tr>
                                <th>编号/手机号</th>
                                <th>作业标题</th>
                                <th>作业作者</th>
                                <th>作业内容</th>
                                <th>点评内容</th>
                                <th>浏览量</th>
                                <th>是否认可</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(count($data))
                                @foreach($data as $v)
                                    <tr id="answer_{{$v->id}}">
                                        <td>{{$v->id}}/{{getUserName($v->user_id)?getUserName($v->user_id)->mobile:''}}</td>
                                        <td>{{$v->title}}</td>
                                        <td>{{getUserName($v->user_id)?getUserName($v->user_id)->nickname:''}}</td>
                                        <td class="autocut" data-attr="{{$v->content}}">{{$v->content}}</td>
                                        <td onclick="commentSelect(this)" data-id="{{$v->id}}">点击查看</td>
                                        <td>{{$v->view}}</td>
                                        <td>{{$v->is_approve == 1?"已认可":"未认可"}}</td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>

                    </div>
                    {{$data->render()}}
                </div>

            </div>
        </div>
    </div>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">课程列表</h4>
                </div>
                <div class="modal-body"></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(".autocut").click(function(){
            var obj = $(this);
            var data = obj.attr("data-attr");
            swal(data);
        })

        //查看点评结果
        function commentSelect(obj){
            var aid    = $(obj).attr('data-id');  //回答id
            var _token = '{{csrf_token()}}';
            var comment= $(obj).attr('data-comment');
            
            if(comment){
                swal(comment);
                return;
            }

            $.ajax({
                url:'/train/ask/tcomment',
                data:{aid:aid, _token:_token},
                type:'POST',
                dataType: 'json',
                success:function(res){
                    console.log(res);
                    if(res.code==1){
                        $("#answer_"+aid).children().eq(4).attr("data-comment",res.msg);
                        swal(res.msg);
                    }else{
                        layer.prompt({title: '请填写点评内容', formType: 2}, function(text,index){
                            layer.close(index);
                            //layer.msg('您最后写下了：'+text);
                            var data = {aid:aid, content:text ,_token:_token};
                            $.ajax({
                                url:'/train/ask/tcommenta',
                                data:data,
                                type:'POST',
                                dataType: 'json',
                                success:function(res){
                                    console.log(res);
                                    if(res.code == 1){
                                        $("#answer_"+aid).children().eq(4).attr("data-comment",text);
                                    }else{
                                        layer.alert(res.msg);
                                    }
                                }
                            });
                            layer.close(index);
                            return true;
                        });
                    }
                }
            });
        }
    </script>
@endsection